package chapter14.Homework;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @Auther: Tx
 * @Date: 2022/5/25 23:04
 */
@SuppressWarnings("all")
public class Homework02 {
    public static void main(String[] args) {
        Car car1 = new Car(4000, "宝马");
        Car car2 = new Car(400000, "宾利");
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList1 = new ArrayList();
        arrayList1.add(car1);
        arrayList1.add(car2);

        arrayList.add(car1);
        arrayList.remove(car1);
        System.out.println(arrayList.contains(car1));
        System.out.println(arrayList.size());
        System.out.println(arrayList.isEmpty());
        arrayList.clear();
        arrayList.addAll(arrayList1);
        System.out.println(arrayList.containsAll(arrayList1));
        System.out.println(arrayList.removeAll(arrayList1));
        System.out.println(arrayList);
        for (Object car : arrayList1) {
            System.out.println(car);
        }
        Iterator iterator = arrayList1.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }

    }
}

class Car {
    private double price;
    private String name;

    public Car(double price, String name) {
        this.price = price;
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Car..{" +
                "price=" + price +
                ", name='" + name + '\'' +
                '}';
    }
}